//
//  SwitchViewController.m
//  SwitchView
//
//  Created by student on 16/2/22.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "SwitchViewController.h"
#import "BlueViewController.h"
#import "YellowViewController.h"

@interface SwitchViewController ()
@property(nonatomic,strong) BlueViewController *blueVC;
@property(nonatomic,strong) YellowViewController *yellowVC;
@property (nonatomic,assign) BOOL curBlue;
@end

@implementation SwitchViewController

- (BlueViewController *)blueVC
{
    if (_blueVC == nil)
    {
        _blueVC = [[BlueViewController alloc] init];
    }
    return _blueVC;
}

- (YellowViewController *)yellowVC
{
    if(!_yellowVC)
    {
        _yellowVC = [[YellowViewController alloc] init];
    }
    return _yellowVC;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self switch:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (IBAction)switch:(id)sender
{
    [UIView beginAnimations:@"ViewFlip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    if(self.curBlue)
    {
        [self.view insertSubview:self.yellowVC.view atIndex:0];
        [self.blueVC.view removeFromSuperview];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    }
    else
    {
        [self.view insertSubview:self.blueVC.view atIndex:0];
        [self.yellowVC.view removeFromSuperview];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    }
    [UIView commitAnimations];
    self.curBlue = !self.curBlue;
}

@end
